package com.cms.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cms.constant.CmsConstant;
import com.cms.service.LotteryService;
import com.cms.service.ReportService;
import com.google.gson.Gson;

@Controller
public class CommonBetController extends BaseController {

	@Autowired
	private LotteryService lotteryService;
	
	@Autowired
	private ReportService reportService;
	

	@RequestMapping(value = "/commBet/deleteCommBet.do")
	public void commonBet(HttpServletRequest req, HttpServletResponse resp)
			throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		try {
			Map<String, Object> lotteryBet = this.buildQueryMap(req);
			lotteryService.deleteLotteryBets(lotteryBet);
			param.put(CmsConstant.STATUS, CmsConstant.SUCCESS_STATUS);
		} catch (Exception e) {
			param.put(CmsConstant.STATUS, CmsConstant.FAIL_STATUS);
			param.put(CmsConstant.MSG, e.getMessage());
		}
		this.renderText(resp, new Gson().toJson(param));
	}
	
	
	
	@RequestMapping(value = "/commBet/betsDetail.do")
	public String betsDetail(HttpServletRequest req, HttpServletResponse resp,ModelMap map) throws Exception 
	{ 
		map.put("betDetail", this.reportService.querySingleResult("queryLotteryBetDetail", this.buildQueryMap(req)));
		return "commbet/commbet_detail.html";
	}
	
	
	@RequestMapping(value = "/commBet/deleteCommBetBatch.do")
	public void deleteCommBetBatch(HttpServletRequest req, HttpServletResponse resp)throws Exception
    {
		Map<String, Object> param = new HashMap<String, Object>();
		try {
			String[]lotteryBets = req.getParameterValues("betsId");
			lotteryService.deleteLotteryBetsBatch(Arrays.asList(lotteryBets));
			param.put(CmsConstant.STATUS, CmsConstant.SUCCESS_STATUS);
		} catch (Exception e) {
			param.put(CmsConstant.STATUS, CmsConstant.FAIL_STATUS);
			param.put(CmsConstant.MSG, e.getMessage());
		}
		this.renderText(resp, new Gson().toJson(param));
	}
}
